Skip to content

Limit User Input Modal to One Window#1730

Merged
oneirocosm merged 5 commits intomainfrom
sylvie/userinput-1window
Jan 16, 2025
Merged

Limit User Input Modal to One Window#1730
oneirocosm merged 5 commits intomainfrom
sylvie/userinput-1window

Conversation

@oneirocosm
Copy link
Contributor

When a connection request is made from a block, only ask for user input in the window that made the request.

This determines the correct block id and sends the modal only to the
window that contains the block that made the initial request.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request introduces several interconnected changes across multiple files in the frontend and backend of the application. The modifications primarily focus on enhancing context management, particularly around user input and connection handling.

The changes involve the removal of debugging console.log statements in the UserInputModal component. Function signatures in global.ts, wave.ts, and userinput.go are updated to include window-specific context and initialization options. A new package genconn is introduced in Go, providing mechanisms to store and retrieve connection-related data within contexts. The connContextKeyType, connData struct, and related functions for managing connection data are added.

Additionally, server-side methods in wshserver.go are modified to incorporate context handling with the new genconn package. These changes enhance how the application manages and tracks connection-related information, especially in scenarios involving user interactions and connection operations.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bd62e4 and d56e19e.

📒 Files selected for processing (1)
  • pkg/wshrpc/wshserver/wshserver.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/wshrpc/wshserver/wshserver.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
frontend/app/store/global.ts (1)

192-192: Consider using debug level logging.

The console.log for user input events might be too verbose for production. Consider using a debug level logger or making it conditional based on development mode.

-                console.log("userinput event handler", event);
+                if (isDev()) {
+                    console.log("userinput event handler", event);
+                }
pkg/wshrpc/wshserver/wshserver.go (2)

685-686: LGTM with a suggestion for improvement.

The context enrichment is properly implemented. Consider extracting the common context enrichment pattern into a helper function since it's used in multiple methods.

+func enrichConnContext(ctx context.Context, blockId string) context.Context {
+    ctx = genconn.ContextWithConnData(ctx, blockId)
+    return termCtxWithLogBlockId(ctx, blockId)
+}

This would reduce code duplication and make future modifications easier.


Line range hint 242-686: Well-structured context enrichment implementation.

The addition of connection data to the context across these methods provides a clean way to track and manage connection-related state. This implementation aligns well with the PR's objective of limiting user input modal to one window by ensuring proper context propagation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a24fe75 and 5ddef29.

📒 Files selected for processing (6)
  • frontend/app/modals/userinputmodal.tsx (0 hunks)
  • frontend/app/store/global.ts (2 hunks)
  • frontend/wave.ts (1 hunks)
  • pkg/genconn/genconn.go (1 hunks)
  • pkg/userinput/userinput.go (3 hunks)
  • pkg/wshrpc/wshserver/wshserver.go (5 hunks)
💤 Files with no reviewable changes (1)
  • frontend/app/modals/userinputmodal.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build for TestDriver.ai
  • GitHub Check: Analyze (go)
🔇 Additional comments (10)
pkg/userinput/userinput.go (2)

66-71: LGTM: Window-scoped event publishing.

The modification to include Scopes: []string{windowId} ensures the user input request is only sent to the specific window that initiated it.


81-94: Verify error handling in the window ID resolution chain.

The window ID resolution logic looks correct but has multiple database lookups that could fail. Consider:

  1. Adding debug logging for troubleshooting
  2. Handling edge cases where any of the IDs might be empty strings

Let's verify the error handling:

✅ Verification successful

Error handling and logging are already robust in the window ID resolution chain.

The code has:

  • Proper error handling with descriptive messages
  • Debug logging for database operations and error cases
  • Implicit empty string validation through the database layer
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential nil checks and error handling patterns in similar code
rg -A 2 "DBFind.*Id" | grep -B 2 "if.*err.*!= nil"

Length of output: 2506


Script:

#!/bin/bash
# Check DB function implementations
ast-grep --pattern 'func DBFind$_(ctx context.Context, id string)'

# Check for logging patterns
rg "log\." -A 2

Length of output: 53993

pkg/genconn/genconn.go (2)

18-24: LGTM: Clean context key implementation.

Good use of a private struct type for the context key to prevent key collisions.


26-42: LGTM: Robust context data management.

The implementation follows best practices:

  • Proper nil checks
  • Immutable context handling
  • Type assertion with proper error handling
frontend/wave.ts (1)

166-166: LGTM: Proper initialization options forwarding.

Correctly passes the window context to the event subscription initialization.

frontend/app/store/global.ts (1)

171-171: LGTM: Window-scoped event subscription.

The changes correctly implement window-scoped user input handling:

  • Function now accepts initialization options
  • User input events are properly scoped to the specific window

Also applies to: 196-196

pkg/wshrpc/wshserver/wshserver.go (4)

24-24: LGTM!

The genconn package import is correctly placed and used consistently throughout the file.


242-244: LGTM!

The context enrichment with connection data is properly implemented, maintaining a logical order of operations.


632-633: LGTM!

The context enrichment is properly implemented, preserving the existing connection handling logic.


662-663: LGTM!

The context enrichment is properly implemented, maintaining compatibility with both WSL and regular connections.

@oneirocosm oneirocosm merged commit e555eaa into main Jan 16, 2025
5 checks passed
@oneirocosm oneirocosm deleted the sylvie/userinput-1window branch January 16, 2025 02:55
xxyy2024 pushed a commit to xxyy2024/waveterm_aipy that referenced this pull request Jun 24, 2025
When a connection request is made from a block, only ask for user input
in the window that made the request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant